//
//  DGScrollViewWrapper.h
//  DGUIKit
//
//  Created by Jinxiao on 4/11/13.
//  Copyright (c) 2013 debugeek. All rights reserved.
//

@class DGScrollViewWrapper;

typedef enum _DGScrollViewAction : NSInteger {
    DGScrollViewActionLoadNew = 0,
    DGScrollViewActionLoadMore,
} DGScrollViewAction;

typedef enum _DGScrollViewStatus : NSInteger {
    DGScrollViewStatusNormal = 0,
    DGScrollViewStatusLoadingNew,
    DGScrollViewStatusLoadingMore,
} DGScrollViewStatus;

@protocol DGScrollViewWrapperDelegate <NSObject>
@optional
- (void)scrollViewWrapperDidTriggerLoadNew:(DGScrollViewWrapper *)scrollViewWrapper;
- (void)scrollViewWrapperDidTriggerLoadMore:(DGScrollViewWrapper *)scrollViewWrapper;

- (BOOL)scrollViewWrapperShouldTriggerLoadNew:(DGScrollViewWrapper *)scrollViewWrapper;
- (BOOL)scrollViewWrapperShouldTriggerLoadMore:(DGScrollViewWrapper *)scrollViewWrapper;
@required
- (void)scrollViewWrapper:(DGScrollViewWrapper *)scrollViewWrapper animatedWithStatus:(DGScrollViewStatus)status action:(DGScrollViewAction)action actionView:(UIView *)actionView progress:(float)progress;
@end

typedef void (^DGScrollViewActionBlock) (DGScrollViewStatus status);
typedef void (^DGScrollViewAnimationBlock) (DGScrollViewStatus status, UIView *animatedView, float progress);

#define kLoadNewHeaderHeight  60.f
#define kLoadMoreFooterHeight 51.f
#define kLoadNewThreshold     65.f
#define kLoadMoreThreshold    60.f

@interface DGScrollViewWrapper : NSObject

@property (readwrite, nonatomic, assign) BOOL supportLoadNew;
@property (readwrite, nonatomic, assign) BOOL supportLoadMore;
@property (readwrite, nonatomic, assign) BOOL enableLoadNew;
@property (readwrite, nonatomic, assign) BOOL enableLoadMore;
@property (readonly, nonatomic, weak) UIScrollView *scrollView;
@property (readwrite, nonatomic, assign) UIEdgeInsets originalInset;
@property (readwrite, nonatomic, weak) id<DGScrollViewWrapperDelegate> delegate;
@property (readonly, nonatomic) DGScrollViewStatus status;
@property (readonly, nonatomic) BOOL initialized;

- (id)initWithScrollView:(UIScrollView *)scrollView;

- (void)initialize;

- (void)triggerLoadNew;
- (void)triggerLoadMore;
- (void)finishLoading;

- (BOOL)isLoadingNew;
- (BOOL)isLoadingMore;

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView;

- (BOOL)shouldTriggerLoadNew;
- (BOOL)shouldTriggerLoadMore;

@end
